import $http from './http'

import {
	BAIDU_CLIENT_ID,
	BAIDU_CLIENT_SECRET
} from '@/config'
import store from '@/store'

/**
 * 自定义
 */
export function custom(data) {
	return $http(data)
}

/**
 * 小程序授权登录
 */
export function smallLogin(data = {}) {
	return $http({
		url: '/api/login/zhiFuBaoLogin',
		data: Object.assign({
			appId: my.getAppIdSync().appId
		}, data)
	})
}

/**
 * 解密手机号
 */
export function decodePhone(data = {}) {
	return $http({
		url: '/api/login/decodePhoneZfb',
		identity: 'user',
		data: data
	})
}

/**
 * 查询新人红包
 */
export function getGiveInfo(data = {}) {
	return $http({
		url: '/api/operator/getGiveInfo',
		identity: 'user',
		data
	})
}

/**
 * 领取新人红包
 */
export function receiveGive(data = {}) {
	return $http({
		url: '/api/operator/receiveGive',
		identity: 'user',
		data
	})
}

/**
 * 服务协议条款--公共接口
 */
export function protocol(data) {
	return $http({
		url: '/api/protocolGuide/getInfo',
		data: Object.assign({
			appId: my.getAppIdSync().appId
		}, data)
	})
}

// 小程序公告
export function protocolss(data) {
	return $http({
		url: '/api/protocolGuide/v2/getInfo',
		data: Object.assign({
			appId: uni.getAccountInfoSync().miniProgram.appId
		}, data)
	})
}

/**
 * 获取平台信息
 */
export function getPlatformInfo(data = {}) {
	return $http({
		url: '/api/operator/getPlatformInfoByZfb',
		identity: 'user',
		data
	})
}

/**
 * 故障报修
 */
export function faultReport(data = {}) {
	return $http({
		url: '/api/fault/report',
		identity: 'user',
		data
	})
}




/**********/
/**
 * 获取百度access_toke
 */
export function getBaiduToken() {
	return $http({
		url: `https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${BAIDU_CLIENT_ID}&client_secret=${BAIDU_CLIENT_SECRET}`,
		method: 'GET',
		default: true,
		data: {}
	})
}

/**
 * 通过百度AI获取图片识别列表
 */
export function scanImageInfo(data) {
	return $http({
		url: `https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general?access_token=${store.state.base.baiduAccessToken}`,
		default: true,
		data: Object.assign({}, data)
	})
}
export function getPromotion(p_id) {
	return $http({
		url: `/api/promotion/getInfo/${p_id}`,
		method: 'GET',
		default: true,
		data: {}
	})
}
export function promotionRecord(data) {
	return $http({
		url: `/api/promotion/promotionRecord`,
		method: 'GET',
		default: true,
		data: data
	})
}


export function getPhone(data) {
	return $http({
		url: `/api/operator/getPhone`,
		method: 'post',
		default: true,
		data: data
	})
}